import * as Yup from 'yup'
// import validator from "validator"
// const Insured options
export const InsuredPersonOptions = [
  { label: 'Client', value: 'insuredClient' },
  { label: "Client's Spouse", value: 'insuredClientSpouse' },
  { label: "Client's Parent", value: 'insuredClientParent' },
  { label: 'Other', value: 'insuredOther' }
]

// Insurance Type options
export const insuranceTypeOptions = [
  { label: 'Primary Insurance', value: 'primary' },
  { label: 'Secondary Insurance', value: 'secondary' },
  { label: 'Other', value: 'otherType' }
]
// const Primary Insured options
export const primaryInsuredPersonOptions = [
  { label: 'Myself', value: 'client' },
  { label: 'Spouse', value: 'clientSpouse' },
  { label: 'Parent/Guardian', value: 'clientParent' },
  { label: 'Other', value: 'other' }
]
// supported image formats
const SUPPORTED_FORMATS_FOR_IMAGE = ['image/jpg', 'image/jpeg', 'image/png']
const SUPPORTED_FORMATS = ['image/jpg', 'image/jpeg', 'image/png', 'application/msword', 'application/pdf']

// validation schema
export const InsuranceFormValidationSchema = Yup.object().shape({
  insuranceType: Yup.string().required('Insurance Type is a required field'),
  primaryInsured: Yup.string().required('Primary Insurance is a required field'),
  InsuredRadio: Yup.string(),
  insuranceCompany: Yup.string(),
  insurancePayer: Yup.string().required('Insurance Payer is a required field'),
  insuranceMemberId: Yup.string()
    .min(3, "Member Id must be more than 3 character's")
    .max(15, "Member Id shouldn't exceed more than 15 character's"),
  insurancePlanId: Yup.string()
    .min(3, "Plan Id must be more than 3 character's")
    .max(15, "Plan Id shouldn't exceed more than 15 character's"),
  insuranceGroupId: Yup.string()
    .min(3, "Group Id  must be more than 3 character's")
    .max(15, "Group Id shouldn't exceed more than 15 character's"),
  memberId: Yup.string()
    .required('Member Id is a required field')
    .min(3, "Member Id  must be more than 3 character's")
    .max(15, "Member Id shouldn't exceed more than 15 character's"),
  planId: Yup.string()
    .min(3, "Plan Id  must be more than 3 character's")
    .max(15, "Plan Id shouldn't exceed more than 15 character's"),
  groupId: Yup.string()
    .min(3, "Group Id  must be more than 3 character's")
    .max(15, "Group Id shouldn't exceed more than 15 character's"),
  copayCoinsurance: Yup.string().max(7, 'Copay Coin Insurance should not exceed more than 7 digits'),
  superBillsPayment: Yup.string().max(8, 'Copay Coin Insurance should not exceed more than 8 digits'),
  deductible: Yup.number(),
  insurancePayerPhone: Yup.string(),
  insurancePayerFax: Yup.string(),
  employerOrSchool: Yup.string()
    .matches(/^[A-Za-z]+$/, 'Employee and school must be Alphabetical')
    .min(5, 'Employee or School field should be more than 5 characters')
    .max(100, 'Employee or School should not exceed more than 100 characters'),
  image: Yup.mixed()
    .test('fileSize', 'File size is too large!', value => {
      if (value) {
        return value.size < 3 * 1024 * 1024
      }
      return true
    })
    .test('fileFormat', 'File format is not supported!', value => {
      if (value) {
        return SUPPORTED_FORMATS_FOR_IMAGE.includes(value.type)
      }
      return true
    }),
  frontImage: Yup.mixed()
    .test('fileSize', 'File size is too large!', value => {
      if (value) {
        return value.size < 3 * 1024 * 1024
      }
      return true
    })
    .test('fileFormat', 'File format is not supported!', value => {
      if (value) {
        return SUPPORTED_FORMATS.includes(value.type)
      }
      return true
    }),
  backImage: Yup.mixed()
    .test('fileSize', 'File size is too large!', value => {
      if (value) {
        return value.size < 3 * 1024 * 1024
      }
      return true
    })
    .test('fileFormat', 'File format is not supported!', value => {
      if (value) {
        return SUPPORTED_FORMATS.includes(value.type)
      }
      return true
    })
})
